import React, { Component } from 'react';
import { Switch, Redirect, Route } from 'react-router-dom'
// 4.封装动态路由表，实现配置式路由并支持多级路由，完成相关页面开发
class Routerview extends Component {
  render() {
    const { routes } = this.props
    return (
      <Switch>
        {
          routes.length > 0 && routes.map((v, i) => {
            return (
              v.path 
                ? <Route key={i} path={ v.path } render={ props=> <v.component { ...props } routes={ v.children }></v.component> }></Route>
                : <Redirect { ...v } key={i}></Redirect>
            )
          })
        }
      </Switch>
    );
  }
}

export default Routerview;
